<template>
  <div class="goodsinfo-container">
    <!-- 轮播图 -->
    <div class="mui-card">
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <swiper :lunbotu="lunbotu" :imgname="'src'"></swiper>
        </div>
      </div>
    </div>

    <!-- 商品购买 -->
    <div class="mui-card">
      <div class="mui-card-header">{{ goodsinfo.title }}</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p class="price">
            市场价：
            <span style="margin-right: 10px"
              ><del>￥{{ goodsinfo.market_price }}</del></span
            >
            销售价：
            <span style="font-size: 16px; color: red; font-weight: bold"
              >￥{{ goodsinfo.sell_price }}</span
            >
          </p>
          <p>购买数量：<nobox :max="goodsinfo.stock_quantity"></nobox></p>
          <div>
            <mt-button type="primary" size="small">立即购买</mt-button>
            <mt-button type="danger" size="small">加入购物车</mt-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 商品参数 -->
    <div class="mui-card">
      <div class="mui-card-header">商品参数</div>
      <div class="mui-card-content">
        <div class="mui-card-content-inner">
          <p>商品货号：{{ goodsinfo.goods_no }}</p>
          <p>库存情况：{{ goodsinfo.stock_quantity }}件</p>
          <p>上架时间：{{ goodsinfo.add_time | dateFormat }}</p>
        </div>
      </div>
      <div class="mui-card-footer btn-area">
        <mt-button type="primary" size="large" plain>图文介绍</mt-button>
        <mt-button type="danger" size="large" plain>商品评论</mt-button>
      </div>
    </div>
  </div>
</template>

<script>
import swiper from "../sub-components/Swiper.vue";
import nobox from "../sub-components/GoodsInfo_nobox.vue";

export default {
  data() {
    return {
      lunbotu: [],
      goodsinfo: {},
    };
  },
  props: ["id"],
  methods: {
    async getlunbotu() {
      const { data } = await this.$http.get("/api/getthumimages/" + this.id);
      if (data.status == 0) {
        this.lunbotu = data.message;
      }
    },
    async getGoodsInfoById() {
      const { data } = await this.$http.get("/api/goods/getinfo/" + this.id);
      if (data.status == 0) {
        this.goodsinfo = data.message[0];
      }
    },
  },
  created() {
    this.getlunbotu();
    this.getGoodsInfoById();
  },
  components: {
    swiper,
    nobox,
  },
};
</script>

<style lang="scss" scoped>
.goodsinfo-container {
  background-color: #eee;
  overflow: hidden;

  .btn-area {
    flex-direction: column;
    button + button {
      //表示两个button后面的那一个
      margin-top: 10px;
    }
  }
}
</style>